package com.qh.resourcehub.usersphere.service.impl;

import com.qh.resourcehub.usersphere.dao.SyncUnifiedUserDao;
import com.qh.resourcehub.usersphere.entity.SyncUnifiedUserRequest;
import com.qh.resourcehub.usersphere.service.SyncUnifiedUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SyncUnifiedUserServiceImpl  implements SyncUnifiedUserService {
    @Resource
    private SyncUnifiedUserDao syncUnifiedUserDao;

    @Override
    public int SyncUnifiedUser(SyncUnifiedUserRequest syncUnifiedUserRequest) {
        int result=0;
        //操作类型（add：新增接口；modify：更新、停用、启用接口，通过唯一标识更新其余字段信息，清空或更新；delete：删除接口）
        String oprationStatus = syncUnifiedUserRequest.getOprationStatus();
        //操作数据：dept：实现部门增删改方法；user：实现人员账号增删改方法）
        String oprationData = syncUnifiedUserRequest.getOprationData();
        if (oprationStatus.equals("add") && oprationData.equals("user")){
            //新增用户
            return  syncUnifiedUserDao.addUser(syncUnifiedUserRequest);
        } else if (oprationStatus.equals("modify") && oprationData.equals("user")) {
            //修改用户
            return syncUnifiedUserDao.saveUser(syncUnifiedUserRequest);
        }else if (oprationStatus.equals("delete") && oprationData.equals("user")) {
            //删除用户
            return syncUnifiedUserDao.delUser(syncUnifiedUserRequest);
        }else if (oprationStatus.equals("add")&& oprationData.equals("dept")) {
            //新增部门
            return  syncUnifiedUserDao.addDeprt(syncUnifiedUserRequest);
        }else if (oprationStatus.equals("modify")&& oprationData.equals("dept")) {
            //更新部门
            return syncUnifiedUserDao.saveDeprt(syncUnifiedUserRequest);
        } else if (oprationStatus.equals("delete")&& oprationData.equals("dept")) {
            //删除部门
            return  syncUnifiedUserDao.delDeprt(syncUnifiedUserRequest);
        }
        return  result;
    }
}
